<%@page import="monster.comm.util.SpringApplicationContextFactory"%>
<%@page import="monster.flight.admin.manager.service.admin.Flight_infoService"%>
<%@page import="monster.flight.comm.util.FlightFactory"%>
<%@page import="monster.comm.util.DateUtil"%>
<%@page import="monster.flight.comm.entity.vo.FlightBay"%>
<%@page import="sun.jdbc.rowset.CachedRowSet"%>
<%@page import="monster.flight.comm.entity.vo.Flight_info"%>
<%@page import="monster.comm.database.DBManager"%>
<%@page import="monster.comm.util.SysConstant"%>
<%@page import="monster.comm.util.UserService"%>
<%@page import="monster.comm.util.Tool"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String type=Tool.getRequest("type",request);
String flight_id=Tool.getRequest("flight_id",request);
String flight_no=Tool.getRequest("flight_no",request);
String ac_type=Tool.getRequest("ac_type",request);
String ac_reg=Tool.getRequest("ac_reg",request);

String bay=Tool.getRequest("bay",request);
String ret="";
if(flight_id.equals(""))flight_id="0";
UserService user = (UserService) session.getAttribute(SysConstant.SESSION_NAME);//获得session里面的登陆信息
if(1==2){
	out.println("{\"id\":-100,\"name\":\"没有登录\"}");
	return;
}else{
	try{
		DBManager db = new DBManager();
		String dateTime = DateUtil.getDate("yyyy-MM-dd HH:mm:ss");
		String date = DateUtil.getDate("yyyy-MM-dd");	
		
		List<String> list = new ArrayList<String>();
		String sql="select staff_sn from plan_info where flight_id="+flight_id;//起飞航班
		CachedRowSet rs = db.getRowSet(sql);
		Set<String> oldSet = new HashSet<String>();//此航班已有工作安排		
		while(rs.next()){
			String sn = Tool.getRsValue(rs,"staff_sn");
			oldSet.add(sn);
		}
		for(String sn : oldSet){
			//删除工作安排
			sql="delete from PLAN_INFO where flight_id="+flight_id+" and staff_sn="+sn;
			list.add(sql);
			//此人之前被新增一定有每天工作任务数不用判断直接更新
			sql="update STAFF_DAY_WORK set TOTAL_WORKNUM=TOTAL_WORKNUM-1,CUR_DAY_WORKNUM=CUR_DAY_WORKNUM-1 where work_date='"+date+"' and staff_sn="+sn;
			list.add(sql);
		}
		//到达航班
		sql="select OP_DATETIME from plan_info where bay='"+bay+"' order by OP_DATETIME desc limit 1";
		rs = db.getRowSet(sql);
		String op_datetime = "";
		
		if(rs.next()){
			op_datetime = Tool.getRsValue(rs,"op_datetime");			
		}
		//查询到达人员
		sql="select STAFF_SN from plan_info  where op_datetime='"+op_datetime+"' and bay='"+bay+"'";
		rs = db.getRowSet(sql);
		oldSet.clear();
		while(rs.next()){
			String sn = Tool.getRsValue(rs,"STAFF_SN");
			oldSet.add(sn);
		}
		for(String sn : oldSet){
			//删除工作安排
			sql="delete from PLAN_INFO where flight_id="+flight_id+" and staff_sn="+sn;
			list.add(sql);
			//此人之前被新增一定有每天工作任务数不用判断直接更新
			sql="update STAFF_DAY_WORK set TOTAL_WORKNUM=TOTAL_WORKNUM-1,CUR_DAY_WORKNUM=CUR_DAY_WORKNUM-1 where work_date='"+date+"' and staff_sn="+sn;
			list.add(sql);
		}
		if(list.size()>0){
			String [] sqls = new String[list.size()];
			list.toArray(sqls);
			db.batchMoreUpdate(sqls);
		}
	
		ret="{\"id\":100}";

		
	}catch(Exception e){
		 e.printStackTrace();
		 ret="{\"id\":-200,\"name\":\"程序异常\"}";
	}
	
	out.println(ret);

}
%>
